package com.martin.fastframe.ui.like.follow

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.MotionEvent
import android.view.View
import android.view.animation.LinearInterpolator
import com.martin.fastframe.R
import com.martin.fastframe.databinding.ActivityLikeFollowBinding
import com.martin.lib_base.base.BaseActivity
import com.martin.lib_base.impl.EmptyViewModel
import com.martin.lib_base.ktx.loge
import dev.utils.app.anim.AnimationUtils

class LikeFollowActivity : BaseActivity<ActivityLikeFollowBinding,EmptyViewModel>() {

    override fun getViewModelClass() = EmptyViewModel::class.java

    override fun layoutId() = R.layout.activity_like_follow

    override fun initOnCreate(savedInstanceState: Bundle?) {
        setViewOnClickListener(binding.rl) { x, y ->
            loge("触发点击事件 x:$x y:$y")
            LikeFollowModel.show(
                x, y, binding.rl, if (binding.switchType.isChecked) {
                    LikeFollowModel.liveLikeFollowData
                } else {
                    LikeFollowModel.videoLikeFollowData
                }
            )
        }
    }

    /**
     * 设置点击监听
     * 返回坐标
     */
    @SuppressLint("ClickableViewAccessibility")
    private fun setViewOnClickListener(view: View, clickCallBack: (x: Int, y: Int) -> Unit) {
        var x = 0f
        var y = 0f
        view.setOnTouchListener { _, event ->
            when (event.action) {
                MotionEvent.ACTION_DOWN -> {
                    x = event.x
                    y = event.y
                }
                MotionEvent.ACTION_UP -> {
                    if (x == event.x && y == event.y) {
                        clickCallBack(event.x.toInt(), event.y.toInt())
                    }
                }
            }
            true
        }
    }

    companion object {
        @JvmStatic
        fun start(context: Context) {
            val starter = Intent(context, LikeFollowActivity::class.java)
            context.startActivity(starter)
        }
    }
}